﻿<template>
  <baseUI :isShow="myConfig.isShow" :label="myConfig.label" :showLabel="myConfig.showLabel"
  :labelSpan="myConfig.labelSpan" :isRequired="myConfig.isRequired" :showErrMsg="showErrMsg" :errMsg="errMsg"
  :commonConfig="commonConfig">
    <el-input v-model = "selectedValue" :size="commonConfig.size" :style = "myConfig.myStyle" :placeholder = "myConfig.other.placeholder"
    :type="myConfig.other.type"
    :row="2"
    :autosize="{minRows: 2, maxRows: 6}"
    :clearable = "myConfig.other.clearable" :disabled = "!myConfig.isEnable" :readonly="myConfig.other.isReadOnly"
    :maxlength = "(Object.keys(myConfig.other).indexOf('maxLength') !== -1 && myConfig.other.maxLength > 0) ? myConfig.other.maxLength : Infinity"
    :show-word-limit = "(Object.keys(myConfig.other).indexOf('maxLength') !== -1 && myConfig.other.maxLength > 0) ? true : false"
    @change="handleChange">
    </el-input>
  </baseUI>
</template>
<script>
import baseComponent from '../baseComponent.vue'
import baseUI from '../baseUI.vue'
export default {
  components: {
    baseComponent, baseUI
  },
  extends: baseComponent,
  mounted () {
  },
  data () {
    return {
    }
  },
  methods: {
    isDataComponent () {
      return true
    },
    handleChange () {
      if (this.myConfig.other.regExpress) {
        let reg = new RegExp(this.myConfig.other.regExpress)
        if (this.getValue() && !reg.test(this.getValue())) {
          this.showErrMsg = true
          this.errMsg = this.myConfig.other.regCheckErr
          return false
        } else {
          this.showErrMsg = false
          this.errMsg = ''
        }
      }
      this.onChange()
    },
    isValid () {
      // 必输校验
      // if (this.myConfig.isRequired && !this.selectedValue) {
      //   this.errMsg = this.myConfig.label + '不可为空'
      //   this.showErrMsg = true
      //   return false
      // }
      if (this.myConfig.other.regExpress) {
        let reg = new RegExp(this.myConfig.other.regExpress)
        if (this.getValue() && !reg.test(this.getValue())) {
          this.showErrMsg = true
          this.errMsg = this.myConfig.other.regCheckErr
          return false
        } else {
          this.showErrMsg = false
          this.errMsg = ''
        }
      }
      this.showErrMsg = false
      return true
    }
  }
}
</script>
<style>
</style>
